<template>
  <div class="active" v-if="projectInfo.taskNode == null">
    <el-form :model="projectInfo" label-width="150px">
      <el-row>
        <el-col
          :span="24"
          style="
            display: flex;
            align-items: center;
            justify-content: space-between;
          "
        >
          <h3>项目信息</h3>
          <el-button type="primary" @click="getInfo">刷新</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="项目编号：">
            <el-input
              v-model="projectInfo.oaCode"
              placeholder="请输入项目编号"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目状态：">
            <el-input
              v-model="projectInfo.status"
              placeholder="请输入项目状态"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目名称：">
            <el-input
              v-model="projectInfo.name"
              placeholder="请输入项目名称"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目公示：">
            <el-input
              v-model="projectInfo.projectNotice"
              placeholder="请输入项目公示"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="发布日期：">
            <el-input
              v-model="projectInfo.publishTime"
              placeholder="请输入发布日期"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="征集截止日期：">
            <el-input
              v-model="projectInfo.applyEndTime"
              placeholder="请输入征集截止日期"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="征集起始日期：">
            <el-input
              v-model="projectInfo.applyStartTime"
              placeholder="请输入征集起始日期"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="评审日期：">
            <el-input
              v-model="projectInfo.auditTime"
              placeholder="请输入评审日期"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div style="display: flex; justify-content: center; align-items: center">
      <el-button
        type="primary"
        style="margin-top: 20px; width: 300px; height: 42px"
        disabled
        >待主持人开启</el-button
      >
    </div>
  </div>
  <div style="padding: 30px" v-else>
    <el-form ref="formRef" :model="projectInfo" label-width="180px">
      <el-form-item label="项目评审开始时间：">
        <el-date-picker
          v-model="projectInfo.auditTime"
          type="datetime"
          placeholder="选择日期时间"
          style="width: 300px"
          disabled
        />
      </el-form-item>
      <el-form-item label="评委获得评审授权时间：">
        <el-date-picker
          v-model="projectInfo.createTime"
          type="datetime"
          placeholder="选择日期时间"
          style="width: 300px"
          disabled
        />
      </el-form-item>
      <el-form-item label="评委评审签到时间：">
        <el-input v-model="form.startCheckTime" style="width: 300px" disabled />
        <span @click="StartSingin" class="link">评委签到签名</span>
      </el-form-item>

      <el-form-item label="评委评审签到签名：">
        <div class="tablet">
          <el-image v-if="form.startCheck" :src="baseURL + form.startCheck">
            <template #error>
              <div class="image-slot"></div>
            </template>
          </el-image>
        </div>
      </el-form-item>
    </el-form>
    <sxb ref="Tablet" @Return="Return" style="display: none" />
    <div style="display: flex; justify-content: center; align-items: center">
      <el-button type="primary" @click="nextStep">下一步</el-button>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRoute } from "vue-router";

import { judgeProjectInfo } from "@/api/project.js";
import { getDictList, getDict, nowTime } from "@/utils/common.js";
import {
  startJudgeSign,
  selectMyApply,
  applySupplierInfoByProjectId,
  auditsign
} from "@/api/examine.js";
import { defineEmits } from "vue";
import sxb from "@/components/sxb.vue";
// 定义 emit 函数
const emit = defineEmits(["next-step"]);
const route = useRoute();
const id = computed(() => route.query.id);

const userInfo = computed(() => JSON.parse(localStorage.getItem("judgeInfo")));
const projectInfo = ref({
  oaCode: "项目编号",
  name: "项目名称",
  noticeUrl: "项目公示",
  status: "征集中",
  publishTime: "2024-11-01",
  applyStartTime: "2024-11-10",
  applyEndTime: "2024-11-10",
  auditTime: "2024-11-11",
  AuditTime: "123",
});
const form = ref({
  AuditTime: "",
  supervisorAuthorizationTime: "",
  startCheckTime: "",
  startCheck:"",
  reviewSignature: "",
  supervisorSignature: "",
  supervisorConfirmationSignature: "",
  confirmationSignatureTime: "",
});
const startCheckTime = ref("");
const judgeId = ref("");
const getInfo = () => {
  judgeProjectInfo({ id: id.value }).then((res) => {
    if (res.code == "200") {
      for (let i = 0; i < res.data.judgeList.length; i++) {
        if (res.data.judgeList[i].userId == userInfo.value.id) {
          judgeId.value = res.data.judgeList[i].id;
          form.value.startCheckTime = res.data.judgeList[i].startCheckTime;
          form.value.startCheck = res.data.judgeList[i].startCheck;
        }
      }
      projectInfo.value = res.data;
      projectInfo.value.supervisorAuthorizationTime = res.data.auditTime;
      projectInfo.value.publishTime = res.data.publishTime
        ? res.data.publishTime.split(" ")[0]
        : "";
      projectInfo.value.applyEndTime = res.data.applyEndTime
        ? res.data.applyEndTime.split(" ")[0]
        : "";
      projectInfo.value.applyStartTime = res.data.applyStartTime
        ? res.data.applyStartTime.split(" ")[0]
        : "";
      projectInfo.value.AuditTime = res.data.auditTime
        ? res.data.auditTime.split(" ")[1]
        : "";
      projectInfo.value.auditTime = res.data.auditTime
        ? res.data.auditTime.split(" ")[0]
        : "";
      projectInfo.value.status = getDict(
        "project_status",
        projectInfo.value.status
      );
    }
  });
};
const Tablet = ref(null);

const baseURL = import.meta.env.VITE_APP_BASE_API;
const Return = (item) => {
  const params = {
    projectId:id.value,
    projectCode: projectInfo.value.oaCode,
    projectJudgeId: judgeId.value,
    signStr: item,
    type: "sign_start",
  };
  auditsign(params).then((res) => {
    if (res.code == "200") {
      form.value.startCheck = res.data;
      getInfo()
    }
  });
};
const StartSingin = () => {
  Tablet.value.beginSign();
};
const nextStep = () => {
  window.location.replace("");
};
onMounted(() => {
  getInfo();
  
});
</script>

<style scoped lang="scss">
@use "./judge";
:deep(.el-input__inner) {
  text-align: center;
}
</style>